/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.storage.api;

import com.jeesite.modules.storage.common.ServerResponse;
import com.jeesite.modules.storage.util.WebUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;


/**
 * 图片表Controller
 */
@RestController(value = "apiimage")
@RequestMapping(value = "/api/image")
public class ImageController extends APIController {

    /**
     * 上传
     * @param file 文件
     * @return 图片
     */
    @RequestMapping(method = RequestMethod.POST,value = "upload")
    @ResponseBody
    public ServerResponse<String> upload(MultipartFile file){
        String image = "/userfiles/image/"+ UUID.randomUUID() + WebUtil.getExtension(file.getOriginalFilename());
        save(file,image);
        return ServerResponse.createBySuccess(200,"上传成功",image);
    }
}